home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 037a / ccunzip.zip / CRC16.ASM < prev    next >
Assembly Source File  |  1989-10-30  |  5KB  |  119 lines

  1. IDEAL
  2. ; This CRC-16 routine and tables were converted from C code discovered
  3. ; in rzsz.arc by Chuck Forsberg.  The comments there are:
  4. ;
  5. ; crctab calculated by Mark G. Mendel, Network Systems Corporation
  6. ;
  7. ; updcrc macro derived from article Copyright (C) 1986 Stephen Satchell.
  8. ;  NOTE: First srgument must be in range 0 to 255.
  9. ;        Second argument is referenced twice.
  10. ;
  11. ; Programmers may incorporate any or all code into their programs,
  12. ; giving proper credit within the source. Publication of the
  13. ; source routines is permitted so long as proper credit is given
  14. ; to Stephen Satchell, Satchell Evaluations and Chuck Forsberg,
  15. ; Omen Technology.
  16. ;
  17. ; <End of rzsz comments>
  18. ;
  19. ; The C macro is:
  20. ;
  21. ; #define updcrc(cp, crc) ( crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  22. ;
  23. ; This routine appears to compute the 16 bit CRC used by XModem and its
  24. ; derivatives.  For transmission, the CRC value should start with 0 and,
  25. ; after the block crc is computed, the value should be updated with two
  26. ; nulls and transmitted high-order byte first.  The computed CRC value
  27. ; on the received block + 2 byte CRC should be zero.
  28. ;
  29. ; This TASM conversion done by:
  30. ;
  31. ;   Edwin T. Floyd [76067h747]
  32. ;   #9 Adams Park Ct.
  33. ;   Columbush GA 31909
  34. ;   404-576-3305 (work)
  35. ;   404-322-0076 (home)
  36. ;
  37. ; Borland's Turbo Assembler - TASM is required to assemble this program.
  38. ;
  39. SEGMENT  code BYTE PUBLIC
  40.          ASSUME cs:code
  41. ;            0
  42. crctab   dw     00000h, 01021h, 02042h, 03063h, 04084h, 050a5h, 060c6h, 070e7h
  43.          dw     08108h, 09129h, 0a14ah, 0b16bh, 0c18ch, 0d1adh, 0e1ceh, 0f1efh
  44. ;            1
  45.          dw     01231h, 00210h, 03273h, 02252h, 052b5h, 04294h, 072f7h, 062d6h
  46.          dw     09339h, 08318h, 0b37bh, 0a35ah, 0d3bdh, 0c39ch, 0f3ffh, 0e3deh
  47. ;            2
  48.          dw     02462h, 03443h, 00420h, 01401h, 064e6h, 074c7h, 044a4h, 05485h
  49.          dw     0a56ah, 0b54bh, 08528h, 09509h, 0e5eeh, 0f5cfh, 0c5ach, 0d58dh
  50. ;            3
  51.          dw     03653h, 02672h, 01611h, 00630h, 076d7h, 066f6h, 05695h, 046b4h
  52.          dw     0b75bh, 0a77ah, 09719h, 08738h, 0f7dfh, 0e7feh, 0d79dh, 0c7bch
  53. ;            4
  54.          dw     048c4h, 058e5h, 06886h, 078a7h, 00840h, 01861h, 02802h, 03823h
  55.          dw     0c9cch, 0d9edh, 0e98eh, 0f9afh, 08948h, 09969h, 0a90ah, 0b92bh
  56. ;            5
  57.          dw     05af5h, 04ad4h, 07ab7h, 06a96h, 01a71h, 00a50h, 03a33h, 02a12h
  58.          dw     0dbfdh, 0cbdch, 0fbbfh, 0eb9eh, 09b79h, 08b58h, 0bb3bh, 0ab1ah
  59. ;            6
  60.          dw     06ca6h, 07c87h, 04ce4h, 05cc5h, 02c22h, 03c03h, 00c60h, 01c41h
  61.          dw     0edaeh, 0fd8fh, 0cdech, 0ddcdh, 0ad2ah, 0bd0bh, 08d68h, 09d49h
  62. ;            7
  63.          dw     07e97h, 06eb6h, 05ed5h, 04ef4h, 03e13h, 02e32h, 01e51h, 00e70h
  64.          dw     0ff9fh, 0efbeh, 0dfddh, 0cffch, 0bf1bh, 0af3ah, 09f59h, 08f78h
  65. ;            8
  66.          dw     09188h, 081a9h, 0b1cah, 0a1ebh, 0d10ch, 0c12dh, 0f14eh, 0e16fh
  67.          dw     01080h, 000a1h, 030c2h, 020e3h, 05004h, 04025h, 07046h, 06067h
  68. ;            9
  69.          dw     083b9h, 09398h, 0a3fbh, 0b3dah, 0c33dh, 0d31ch, 0e37fh, 0f35eh
  70.          dw     002b1h, 01290h, 022f3h, 032d2h, 04235h, 05214h, 06277h, 07256h
  71. ;            A
  72.          dw     0b5eah, 0a5cbh, 095a8h, 08589h, 0f56eh, 0e54fh, 0d52ch, 0c50dh
  73.          dw     034e2h, 024c3h, 014a0h, 00481h, 07466h, 06447h, 05424h, 04405h
  74. ;            B
  75.          dw     0a7dbh, 0b7fah, 08799h, 097b8h, 0e75fh, 0f77eh, 0c71dh, 0d73ch
  76.          dw     026d3h, 036f2h, 00691h, 016b0h, 06657h, 07676h, 04615h, 05634h
  77. ;            C
  78.          dw     0d94ch, 0c96dh, 0f90eh, 0e92fh, 099c8h, 089e9h, 0b98ah, 0a9abh
  79.          dw     05844h, 04865h, 07806h, 06827h, 018c0h, 008e1h, 03882h, 028a3h
  80. ;            D
  81.          dw     0cb7dh, 0db5ch, 0eb3fh, 0fb1eh, 08bf9h, 09bd8h, 0abbbh, 0bb9ah
  82.          dw     04a75h, 05a54h, 06a37h, 07a16h, 00af1h, 01ad0h, 02ab3h, 03a92h
  83. ;            E
  84.          dw     0fd2eh, 0ed0fh, 0dd6ch, 0cd4dh, 0bdaah, 0ad8bh, 09de8h, 08dc9h
  85.          dw     07c26h, 06c07h, 05c64h, 04c45h, 03ca2h, 02c83h, 01ce0h, 00cc1h
  86. ;            F
  87.          dw     0ef1fh, 0ff3eh, 0cf5dh, 0df7ch, 0af9bh, 0bfbah, 08fd9h, 09ff8h
  88.          dw     06e17h, 07e36h, 04e55h, 05e74h, 02e93h, 03eb2h, 00ed1h, 01ef0h
  89.  
  90.          MODEL TPASCAL
  91.  
  92. PUBLIC   UpdateCRC16
  93. PROC     UpdateCRC16 FAR initcrc:WORD,inbuf:DWORD,inlen:WORD
  94. ; UpdateCRC16 takes an initial CRC value and updates it with inlen bytes from
  95. ; inbuf. The updated CRC is returned in AX.  The Pascal declaration is:
  96. ; Function UpdateCRC16(InitCRC : Word; Var InBuf; InLen : Word) : Word;
  97. ; Stomps registers: AX,BX,CX,SI
  98.          push   ds
  99.          lds    si,[inbuf]    ; ds:si := ^inbuf
  100.          mov    ax,[initcrc]  ; ax := initcrc
  101.          mov    cx,[inlen]    ; cx := inlen
  102.          or     cx,cx
  103.          jz     @@done
  104. @@loop:
  105.          xor    bh,bh
  106.          mov    bl,ah
  107.          mov    ah,al
  108.          lodsb
  109.          shl    bx,1
  110.          xor    ax,[crctab+bx]
  111.          loop   @@loop
  112. @@done:
  113.          pop    ds
  114.          ret
  115. ENDP
  116.  
  117. ENDS
  118. END
  119.